/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import Model.Category;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Admin
 */
public class dialogNewCategory extends javax.swing.JDialog {

    /**
     * Creates new form dialogNewCategory
     */
    ObjectOutputStream out;
    ObjectInputStream in;
    public dialogNewCategory(java.awt.Frame parent, boolean modal,ObjectOutputStream out,ObjectInputStream in) {
        super(parent, modal);        
        this.out=out;
        this.in=in;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtNewCategory = new javax.swing.JTextField();
        btnOKCategory = new javax.swing.JButton();
        btnCancelCategory = new javax.swing.JButton();
        lbCategory = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("New Category");
        setResizable(false);

        txtNewCategory.setText("Typing new category");
        txtNewCategory.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtNewCategoryMouseClicked(evt);
            }
        });

        btnOKCategory.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/ButtonOK32px.png"))); // NOI18N
        btnOKCategory.setText("OK");
        btnOKCategory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKCategoryActionPerformed(evt);
            }
        });

        btnCancelCategory.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/ButtonCancel.png"))); // NOI18N
        btnCancelCategory.setText("Cancel");
        btnCancelCategory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelCategoryActionPerformed(evt);
            }
        });

        lbCategory.setText("New Category");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addComponent(txtNewCategory, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(btnOKCategory, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancelCategory))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addComponent(lbCategory)))
                .addContainerGap(62, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbCategory)
                .addGap(37, 37, 37)
                .addComponent(txtNewCategory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnOKCategory)
                    .addComponent(btnCancelCategory))
                .addGap(52, 52, 52))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOKCategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKCategoryActionPerformed
        // TODO add your handling code here:
        String newCategory=txtNewCategory.getText();
        try {
            out.writeObject("insertCategory");
            out.writeObject(newCategory);
            String tb=(String)in.readObject();
            JOptionPane.showMessageDialog(this,tb);
        } catch (Exception e) {
            e.printStackTrace();
        }
            
    }//GEN-LAST:event_btnOKCategoryActionPerformed

    private void btnCancelCategoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelCategoryActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_btnCancelCategoryActionPerformed

    private void txtNewCategoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtNewCategoryMouseClicked
        // TODO add your handling code here:
        if(txtNewCategory.getText().equals("Typing new category")){
            txtNewCategory.setText("");
        }
    }//GEN-LAST:event_txtNewCategoryMouseClicked

    /**
     * @param args the command line arguments
     */   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelCategory;
    private javax.swing.JButton btnOKCategory;
    private javax.swing.JLabel lbCategory;
    private javax.swing.JTextField txtNewCategory;
    // End of variables declaration//GEN-END:variables
}
